import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/* 路由模块(Modules) */
// import nestedRouter from './modules/nested'

/**
* name:'router-name'             name 是给<keep-alive>使用,所以每个路由必须设置!!!
* meta : {
    roles: ['admin','editor']    将控制页面权限(可以设置多个权限,数组的形式)
    title: 'title'               页面名称,用来显示在菜单栏和面包屑以及顶部上
    noCache: true                如果设置成 true, 该页面不会被缓存(default is false)
  }
**/

// constantRoutes 不需要权限验证 和 登录验证的页面路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index'),
        meta: {
          admin: true
        }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta: {
      admin: true
    }
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  }
]

export default new Router({
  // mode: 'history', // 服务端支持的情况下, 可以设置
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

// asyncRoutes 需要进行权限验证 和 路由验证
export const asyncRoutes = [
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/index/index'),
        name: 'index',
        meta: {
          title: '首页',
          noCache: true
        }
      }
    ]
  },
  {
    path: '',
    component: Layout,
    children: [
      {
        path: 'test',
        component: () => import('@/views/test/test'),
        name: 'test',
        meta: {
          title: '测试'
        }
      }
    ]
  },
  /** 当路由表太长时，可以将其拆分为小模块**/
  // nestedRouter,

  // 外链
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://zhuaiye.top',
        meta: {
          title: 'externalLink',
          icon: 'link',
          admin: true
        }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]
